from ui.login import Ui_LoginMainWindow
from service import *
from PyQt5 import QtCore
from admin import *
from user import *
import globalvar

class LoginMainWindow(Ui_LoginMainWindow):
    def __init__(self, MainWindow) -> None:
        super().setupUi(MainWindow)
        self.pushButton_2.clicked.connect(self.login) # type: ignore

    def login(self):
        username = self.lineEdit.text()
        password = self.lineEdit_2.text()
        lmss = LMSService()
        res, role, globalvar.user_id = lmss.login(username, password)
        if res:
            if role == "admin":
                self.newWindow=AdminMainWindow()
                self.newWindow.show()
            else:
                self.newWindow=UserMainWindow()
                self.newWindow.show()
        else:
            _translate = QtCore.QCoreApplication.translate
            self.label_3.setText(_translate("LoginMainWindow", "帐号或密码错误"))